package com.kc.data.common.service.impl;

import com.kc.data.common.domain.model.BizGoodsPriceOutRate;
import com.kc.data.common.mapper.BizGoodsPriceOutRateMapper;
import com.kc.data.common.service.IBizSetGoodsPriceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class BizSetGoodsPriceServiceImpl implements IBizSetGoodsPriceService {
    @Resource
    private BizGoodsPriceOutRateMapper bizGoodsPriceOutRateMapper;
    /**
     * 根据成本价获取商品销售价
     * @param costPrice
     * @return
     */
    @Override
    public BigDecimal getGoodsSalePriceByCost(Double costPrice) {
        BizGoodsPriceOutRate bizGoodsPriceOutRate = new BizGoodsPriceOutRate();
        bizGoodsPriceOutRate.setId(1);
        bizGoodsPriceOutRate = bizGoodsPriceOutRateMapper.selectById(bizGoodsPriceOutRate.getId());
        BigDecimal totalRate = bizGoodsPriceOutRate.getRedPacketsRate().add(bizGoodsPriceOutRate.getSaleRate())
                .add(bizGoodsPriceOutRate.getTaxRate()).add(bizGoodsPriceOutRate.getProfitRate()).add(bizGoodsPriceOutRate.getBusinessRate());
        BigDecimal rate = (bizGoodsPriceOutRate.getTotalRate().subtract(totalRate)).divide(new BigDecimal(100));
        BigDecimal cost = new BigDecimal(costPrice);
        return cost.divide(rate,0,BigDecimal.ROUND_HALF_UP);
    }
}
